using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

using GURUCORE.Framework.Core.Util.Localization;
using GURUCORE.Framework.Core.Util.Customization;

namespace GURUCORE.Portal.AspNet.Control.Localized
{

	#region RequiredFieldValidator
	public class LocalizedRequiredFieldValidator : RequiredFieldValidator , ILocalizable
	{
		protected override void Render(HtmlTextWriter writer) 
		{
			if (HttpContext.Current != null)
			{
				System.Web.UI.Control ctlNamingContainer = this.NamingContainer;
				if (ctlNamingContainer == null)
				{
					base.Render(writer);
					return;
				};
				while ( !(ctlNamingContainer is UserControl || ctlNamingContainer is Page))
				{
					ctlNamingContainer = ctlNamingContainer.NamingContainer;
					if (ctlNamingContainer == null)
					{
						base.Render(writer);
						return;
					};
				}

				string sText = ResourceManager.GetString(ctlNamingContainer.GetType().BaseType.FullName, this.ID);

				if (sText != string.Empty)
				{
					this.ErrorMessage = sText;
				}
			}
			base.Render (writer);
		}

		protected override void RegisterValidatorDeclaration()
		{
			string text1 = "document.getElementById(\"" + this.ClientID + "\")";

            this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", text1);
			// this.Page.RegisterArrayDeclaration("Page_Validators", text1);
		}
	}
	#endregion

	#region RangeValidator
	public class LocalizedRangeValidator : RangeValidator, ILocalizable 
	{
		protected override void Render(HtmlTextWriter writer) 
		{
			if (HttpContext.Current != null)
			{
				System.Web.UI.Control ctlNamingContainer = this.NamingContainer;
				if (ctlNamingContainer == null)
				{
					base.Render(writer);
					return;
				};
				while (!(ctlNamingContainer is UserControl || ctlNamingContainer is Page))
				{
					ctlNamingContainer = ctlNamingContainer.NamingContainer;
					if (ctlNamingContainer == null)
					{
						base.Render(writer);
						return;
					};
				}

				string sText = ResourceManager.GetString(ctlNamingContainer.GetType().BaseType.FullName, this.ID);

				if (sText != string.Empty)
				{
					this.ErrorMessage = sText;
				}
			}
			base.Render (writer);
		}
		protected override void RegisterValidatorDeclaration()
		{
			string text1 = "document.getElementById(\"" + this.ClientID + "\")";
            this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", text1);
			// this.Page.RegisterArrayDeclaration("Page_Validators", text1);
		}
	}
	#endregion

	#region Custom Validator
	public class LocalizedCustomValidator : CustomValidator, ILocalizable 
	{
		protected override void Render(HtmlTextWriter writer) 
		{
			if (HttpContext.Current != null)
			{
				System.Web.UI.Control ctlNamingContainer = this.NamingContainer;
				if (ctlNamingContainer == null)
				{
					base.Render(writer);
					return;
				};
				while (!(ctlNamingContainer is UserControl || ctlNamingContainer is Page))
				{
					ctlNamingContainer = ctlNamingContainer.NamingContainer;
					if (ctlNamingContainer == null)
					{
						base.Render(writer);
						return;
					};
				}

				string sText = ResourceManager.GetString(ctlNamingContainer.GetType().BaseType.FullName, this.ID);

				if (sText != string.Empty)
				{
					this.ErrorMessage = sText;
				}
			}
			base.Render (writer);
		}
		protected override void RegisterValidatorDeclaration()
		{
			string text1 = "document.getElementById(\"" + this.ClientID + "\")";
            this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", text1);
            // this.Page.RegisterArrayDeclaration("Page_Validators", text1);
            
		}
	}
	#endregion

	#region RegularExpressionValidator
	public class LocalizedRegularExpressionValidator : RegularExpressionValidator, ILocalizable 
	{
		protected override void Render(HtmlTextWriter writer) 
		{
			if (HttpContext.Current != null)
			{
				System.Web.UI.Control ctlNamingContainer = this.NamingContainer;
				if (ctlNamingContainer == null)
				{
					base.Render(writer);
					return;
				};
				while (!((ctlNamingContainer is UserControl) || (ctlNamingContainer is Page)))
				{
					ctlNamingContainer = ctlNamingContainer.NamingContainer;
					if (ctlNamingContainer == null)
					{
						base.Render(writer);
						return;
					};
				}

				string sText = ResourceManager.GetString(ctlNamingContainer.GetType().BaseType.FullName, this.ID);

				if (sText != string.Empty)
				{
					this.ErrorMessage = sText;
				}
			}
			base.Render (writer);
		}
		protected override void RegisterValidatorDeclaration()
		{
			string text1 = "document.getElementById(\"" + this.ClientID + "\")";
			this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", text1);
            // this.Page.RegisterArrayDeclaration("Page_Validators", text1);
		}
	}
	#endregion

	#region CompareValidator
	public class LocalizedCompareValidator : CompareValidator, ILocalizable
	{
		protected override void Render(HtmlTextWriter writer) 
		{
			if (HttpContext.Current != null)
			{
				System.Web.UI.Control ctlNamingContainer = this.NamingContainer;
				if (ctlNamingContainer == null)
				{
					base.Render(writer);
					return;
				};
				while (!(ctlNamingContainer is UserControl || ctlNamingContainer is Page))
				{
					ctlNamingContainer = ctlNamingContainer.NamingContainer;
					if (ctlNamingContainer == null)
					{
						base.Render(writer);
						return;
					};
				}

				string sText = ResourceManager.GetString(ctlNamingContainer.GetType().BaseType.FullName, this.ID);

				if (sText != string.Empty)
				{
					this.ErrorMessage = sText;
				}
			}
			base.Render (writer);
		}
	   
		protected override void RegisterValidatorDeclaration()
		{
			string text1 = "document.getElementById(\"" + this.ClientID + "\")";
            this.Page.ClientScript.RegisterArrayDeclaration("Page_Validators", text1);
			// this.Page.RegisterArrayDeclaration("Page_Validators", text1);
		}
	}
	#endregion
}
